package data;

import java.util.ArrayList;
import java.util.Iterator;

@SuppressWarnings("rawtypes")
public class ListInterIterator<E> implements Iterator {
	
	ArrayList<E> list=new ArrayList<E>();
	int position=0;
    
	public ListInterIterator(ArrayList<E> list){
		this.list=list;
	}

	@Override
	public boolean hasNext() {
		if(position>=list.size()||list.get(position)==null){
			return false;
		}
		else{
			return true;
		}
	}

	@Override
	public E next() {
		// TODO Auto-generated method stub
		E temp= list.get(position);
		position++;
		return temp;
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		try {
			throw new Exception();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public String toString(){
		String s = null;
		while(hasNext()){
			E item=(E) next();
			s=item.toString();
		}
		s=s+"\n";
		return s;
	}
	
	public ArrayList<E> toArray(){
		ArrayList<E> thelist=new ArrayList<E>();
		while(hasNext()){
			E item=(E) next();
			thelist.add(item);
		}
		return thelist;
	}
	

}
